<template>
  <div class="menu-banner">
    <div class="menu-container" @mouseleave="bannerMenuHide()">
<!--      只加-->
<!--      <div>
        <div v-for="item in outputLists" :key="item.id">{{item.name}}</div>
      </div>-->
      <!-- 循环所有的分类 -->
      <ul class="menu-list">
        <li
            class="list-item"
            v-for="(item, index) in menus"
            :key="index"
            @mouseenter="bannerMenuShow(item.type)"
        ><!--悬浮显示，传入当前分类type的id调用bannerMenuShow函数，把当前分类goods传入listInfoData[]-->
          <a :href="item.url" target="blank">{{ item.value }}</a>
          <i class="el-icon-arrow-right"></i>
        </li>
      </ul>
    </div>
    <div
        class="menu-info"
        v-show="bannerMenuFlag"
        @mouseleave="bannerMenuHide()"
        @mouseenter="bannerMenuShow()"
    >
      <ul
          class="menu-info-list"
          v-for="(list, key) in menuListMatch"
          :key="key"
          :data-key="key"
      ><!--menuListMatch为listInfoData的计算属性，6个分 -->
        <li
            class="info-list-item"
            v-for="(item, index) in list"
            :key="index"
            :data-index="index"
        >

            <router-link :to="{ path: '/goods/details', query: {productID:item.id,seckill:seckill} }">
            <img :src="$target+item.imgUrl" :alt="item.goodsName" />
            <span class="">{{ item.goodsName }}</span>
            </router-link>
        </li>
      </ul>
    </div>
<!--    <banner :banners="banners"></banner>-->
  </div>
</template>

<script>
/*import Banner from "./Banner";*/

export default {
  name:"MenuBanner",
  props: ["lists", "isMore", "isDelete","seckill"],
  data() {
    return {

      bannerMenuFlag: false,
      menuTimer: "",
      listInfoData: [],
      // 一级分类
      menus: [

      ],
     //二级展示
      products:{
      }
    };
  },
  watch: {
    lists(newVal) {
      console.log("监听lists:", newVal);

      let homeMenusList= newVal;

      for (let i = 0; i < homeMenusList.length; i++) {
        const cate = homeMenusList[i];
        this.menus.push({//导航栏
          value:cate.typeName,
          type:cate.id,
          url:"/#/searchResult/"})
        this.products[cate.id]= cate.goodsList
        }

    }
  },
  methods: {
    bannerMenuHide() {
      this.menuTimer = setTimeout(() => {
        this.bannerMenuFlag = false;
      }, 300);
    },
    bannerMenuShow(type) {   //2
      if (type) {
        this.listInfoData = this.products[type];
      }

      this.bannerMenuFlag = true;
      clearTimeout(this.menuTimer);
    },
    innit() {

      }



    },

  // 生命周期钩子函数
  mounted() {
    this.innit();
  },
  computed: {



    menuListMatch() {
      const matchData = [];
      if (this.listInfoData && this.listInfoData.length) {
        for (let i = 0; i < this.listInfoData.length; i += 6) {
          matchData.push(this.listInfoData.slice(i, i + 6));
        }
      }
      return matchData;

    },
  }
  /*components: {
    Banner: Banner,
  },*/
};
</script>

<style lang="less">
.menu-banner {
  position: relative;
  width: 1226px;
  height: auto;
  margin: 0 auto;
  .menu-container {
    position: absolute;
    left: 0;
    top: 0;
    width: 235px;
    height: auto;
    background: rgba(0, 0, 0, 0.3);
    z-index: 10;
  }
}

.menu-list {
  padding: 20px 0;
  height: 460px;
  .list-item {
    display: flex;
    padding-left: 30px;
    &:hover {
      background-color: #ff6700;
    }

    a {
      position: relative;
      display: inline-block;
      width: 170px;
      height: 42px;
      line-height: 42px;
      color: #fff;
      text-align: left;
      background-color: transparent;
    }

    i {
      font-size: 22px;
      color: #e0e0e0;
      line-height: 42px;
    }
  }
}

.menu-info {
  position: absolute;
  display: flex;
  flex-flow: row nowrap;
  justify-content: flex-start;
  left: 235px;
  top: 0;
  z-index: 11;
  border: 1px solid #e0e0e0;
  box-shadow: 3px 8px 16px rgba(0, 0, 0, 0.18);
  .menu-info-list {
    width: 248px;
    height: 500px;
    margin: 0;
    padding: 0;
    list-style: none;
    background: #fff;
    a {
      display: flex;
      padding: 18px 20px;
      line-height: 40px;
      color: #333;
      img {
        width: 40px;
        height: 40px;
        margin-right: 12px;
        vertical-align: middle;
      }

      span {
        width: 172px;
        line-height: 40px;
        font-size: 14px;
        text-align: start;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
      }

      &:hover {
        span {
          color: #ff6700;
        }
      }
    }
  }
}
</style>